// let root='http://localhost:3000'
// let root='http://192.168.43.4:3000'
// let root='http://192.168.1.20:3000'
let root="http://47.92.2.110"



export default {
  
  get:async function(url){
    let arr=url.split("?")
    let res
    if(arr.length==1){
      res=await fetch(`${root+url}?token=${localStorage.getItem("token")}`);
    }else{
      res=await fetch(`${root+url}&token=${localStorage.getItem("token")}`);
    }
    // let res=await fetch(`${root+url}`)
    let data=await res.json()
    return data
      
    // 判断数据
  },



  post:async function(obj){
    /*
    obj.url
    obj.data
    obj.form
    */
   let formdata
    if(obj.form){
      formdata=new FormData(obj.form)
    }else if(obj.data){
      formdata=new FormData()
      for(let key in obj.data){
        formdata.append(key,obj.data[key])
      }
    }
formdata.append('token',localStorage.getItem("token"))



    let res = await fetch(`${root+obj.url}`,{
      method:"POST",
      body:formdata
    })
    let data =await res.json()
    return data
  }
}